package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.entity.SysMenu;
import com.itheima.advantagesup.service.SysMenuService;
import com.itheima.advantagesup.vo.MenuVO;
//import com.itheima.advantagesup.vo.MenuVo2;
import com.itheima.advantagesup.vo.MenuVO2;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//表示当前类下所有的方法返回值做为响应数据,方法的返回值，如果是一个POJO对象或集合时，会先转换为JSON格式**，在响应给浏览器.
@RequestMapping("/sys_menu")
@RequiredArgsConstructor
@Slf4j
public class MenuController {

    private final SysMenuService sysMenuService;

    /**
     * /sys_menu/allData 查询所有菜单
     * @return
     */
    @GetMapping("/allData")
    public R<List<SysMenu>> getAllData(){
        //SysMenu:里面有SysMenu,和List<SysMenu>
        List<SysMenu> list = sysMenuService.getAllData();
        return R.success(list);
    }
    /**
     * 新增菜单
     */
    @PostMapping("/add")
    public R addMenu(@RequestBody MenuVO menuVO){
        sysMenuService.addMenu(menuVO);
        return R.success();
    }
    /**
     * 根据id删除菜单
     */
    @GetMapping("/del")
    public R deleteById(Integer id){
        sysMenuService.deleteById(id);
        return R.success();
    }
    @PostMapping("/update")
    public R updateMenu(@RequestBody MenuVO menuVO){
        sysMenuService.updateMenu(menuVO);
        return R.success();
    }
    @GetMapping("/rowInfo")
    public R rowInfo(Integer id){
        MenuVO2 menuVo2 = sysMenuService.rowInfo(id);
        return R.success(menuVo2);
    }
}
